# -*- coding: utf-8 -*-

# Copyright (C) 2011 Dimitri Linten

#This file is part of pyQuiz.
#
#pyQuiz is free software: you can redistribute it and/or modify
#it under the terms of the GNU Lesser General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#ThunderStorm is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU Lesser General Public License for more details.
#
#You should have received a copy of the GNU Lesser General Public License
#along with pyQuiz.  If not, see <http://www.gnu.org/licenses/>.

"""
Simple typical  plot
"""

import numpy as np
import warnings
import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib.pyplot import figure


# add scores
# add multiple plots in case to many rooms
# colors on bars ( link with a marker)


class CurrentScores(object):
    """A simple CurrentScores
    """
    def __init__(self, figure, data):
        
        mpl.rc('xtick',labelsize= 'large')
        mpl.rc('ytick',labelsize= 'large')
        mpl.rc('figure',edgecolor= 'white')
        mpl.rc('font', size =15)
        
        
        ax= figure.add_subplot(111)
        
        ynames=[]
        val=[]
        # Format data to fit Plots
        #print sorted(data.items(), key=lambda x: x[1])
        for w in sorted(data.items(), key=lambda x: x[1]):
            ynames.append(w[0])
            val.append(w[1])
            
        pos=np.arange(len(val))+0.5
        val=np.array(val)
        width=0.35
        
        rects1=ax.barh(pos,val,width,align='center')
        ax.set_yticks(pos)
        ax.set_yticklabels(tuple(ynames))
        ax.set_xlabel('Punten')
        ax.set_title('Finale punten')
        ax.grid(True)
        
        def autolabel(rects,widthbar):
        # attach some text labels
            for rect in rects:
                height = rect.get_height()
                width = rect.get_width()
                ax.text( width*1.05,rect.get_y()+widthbar/2, '%d'%int(width),
                        ha='center', va='bottom',size=20)
        
        autolabel(rects1,width)

        draw = figure.canvas.draw
        draw()

class ScoresSchift(object):
    """A simple CurrentScores
    """
    def __init__(self, figure, data):
        
        mpl.rc('xtick',labelsize= 'large')
        mpl.rc('ytick',labelsize= 'large')
        mpl.rc('figure',edgecolor= 'white')
        mpl.rc('font', size =15)
        
        ax= figure.add_subplot(111)
        
        ynames=[]
        val=[]
        # Format data to fit Plots
        #print sorted(data.items(), key=lambda x: x[1])
        for w in sorted(data.items(), key=lambda x: x[1]):
            ynames.append(w[0])
            val.append(w[1])
        
        ynames=ynames[::-1]
        val=val[::-1]
        
        pos=np.arange(len(val))+0.5
        val=np.array(val)
        width=0.35
        
        rects1=ax.barh(pos,val,width,align='center')
        ax.set_yticks(pos)
        ax.set_yticklabels(tuple(ynames))
        ax.set_xlabel('Punten')
        ax.set_title('Schifting')
        ax.grid(True)
        
        def autolabel(rects,widthbar):
        # attach some text labels
            for rect in rects:
                height = rect.get_height()
                width = rect.get_width()
                ax.text( width*1.05,rect.get_y()+widthbar/2, '%d'%int(width),
                        ha='center', va='bottom',size=20)
        
        autolabel(rects1,width)

        draw = figure.canvas.draw
        draw()


class CurrentScoresTopic(object):
    """A simple CurrentScores
    """
    def __init__(self, figure, data, naam):
        
        mpl.rc('xtick',labelsize= 'large')
        mpl.rc('ytick',labelsize= 'large')
        mpl.rc('figure',edgecolor= 'white')
        mpl.rc('font', size =15)
        
        ax= figure.add_subplot(111)
        
        ynames=[]
        val=[]
        # Format data to fit Plots
        #print sorted(data.items(), key=lambda x: x[1])
        for w in sorted(data.items(), key=lambda x: x[1]):
            ynames.append(w[0])
            val.append(w[1])
            
        pos=np.arange(len(val))+0.5
        val=np.array(val)
        width=0.35
        
        rects1=ax.barh(pos,val,width,align='center')
        ax.set_yticks(pos)
        ax.set_yticklabels(tuple(ynames))
        ax.set_xlabel('Punten')
        ax.set_title(naam)
        ax.grid(True)
        
        def autolabel(rects,widthbar):
        # attach some text labels
            for rect in rects:
                height = rect.get_height()
                width = rect.get_width()
                ax.text( width*1.05,rect.get_y()+widthbar/2, '%d'%int(width),
                        ha='center', va='bottom',size=20)
        
        autolabel(rects1,width)

        draw = figure.canvas.draw
        draw()


if __name__=="__main__":
    
    from matplotlib.pyplot import figure
    from simple_plots import CurrentScores
    import matplotlib
    
    import pylab as P
#    P.figure()
    P.fig = CurrentScores(P.figure(),{'a':2,'b':4,'c':1})
    P.show()
    

    
    
    